﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class UpgradeSendback : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitialPage();
            }
        }

        private void InitialPage()
        {
            UpgradeService service = new UpgradeService();
            UpgradeForm upForm = service.GetSendFormDetailByUpgradeID(long.Parse(Request.QueryString[Constants.QUERYSTR_UPGRADE_ID]));
            productTypeLabel.Text = upForm.ApplicationProduct.ProductType.ProductTypeName;
            serialNumberLabel.Text = upForm.ApplicationProduct.ProductSerialNumber;
            problemTypeLabel.Text = upForm.ApplicationProduct.ProblemType.Name;
            decriptionLabel.Text = upForm.ApplicationProduct.ProductProblemDescription;
            appearanceLabel.Text = upForm.ApplicationProduct.ProductAppearance;
            repairTypeLabel.Text = upForm.ApplicationProduct.ProductRepairType;
            examineResultLabel.Text = upForm.ApplicationProduct.Remark;
            upgradeReason.Text = upForm.UpgradeReason;

            RMACodeLabel.Text = upForm.Code;
            companyLabel.Text = upForm.ApplicationProduct.ApplicationForm.User.CompanyName;
            addressLabel.Text = upForm.ApplicationProduct.ApplicationForm.User.UserAddress;
            contactLabel.Text = upForm.ApplicationProduct.ApplicationForm.User.UserName;
            phoneNumberLabel.Text = upForm.ApplicationProduct.ApplicationForm.User.UserPhone;
            faxLabel.Text = upForm.ApplicationProduct.ApplicationForm.User.UserFax;
            emailLabel.Text = upForm.ApplicationProduct.ApplicationForm.User.UserEmail;

            receiveTimeLabel.Text = upForm.ReceiveTime.HasValue ? upForm.ReceiveTime.Value.ToString("yyyy-MM-dd") : "";
            sendTimeLabel.Text = DateTime.Now.ToString("yyyy-MM-dd");
            dealTime.Text = upForm.DealWithTime.HasValue ? upForm.DealWithTime.Value.ToString("yyyy-MM-dd") : "";
        }
        
        protected void saveLinkButton_Click(object sender, EventArgs e)
        {
            try
            {
                UpgradeService service = new UpgradeService();
                UpgradeForm upForm = service.GetUpgradeFormByID(long.Parse(Request.QueryString[Constants.QUERYSTR_UPGRADE_ID]));
                upForm.SendBackTime = Convert.ToDateTime(sendTimeLabel.Text);
                upForm.Status = "升级-发货待平台收货确认";
                service.Update(upForm);
                ClientScript.RegisterStartupScript(this.GetType(), "tip", "alert('发货成功，待平台收货确认');location.href='UpgradeNeedSendBack.aspx';", true);
            }
            catch (Exception ex)
            {
                LogUtility.LogUtilityIntance.LogException(ex, "UpgradeSendback.aspx::saveLinkButton_Click");
                throw ex;
            }
        }
    }
}
